Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ras): unify ESP connector strategy for data events #3360

Merged
merged 38 commits into from
Aug 30, 2024

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Aug 22, 2024

All Submissions:

Changes proposed in this Pull Request:

Following the work from #3359, this PR unifies the ESP connectors into one ESP_Connector using the recently implemented Newspack\Reader_Activation\ESP_Sync::sync() method for syncing contacts via data events handlers.

The only new behavior from this change is that the newsletter_selection field will no longer be exclusive to ActiveCampaign. It's a compromise for having a single connector handling any ESP the Newspack Newsletters plugin supports. If we find that this field should not live anywhere outside ActiveCampaign, we have 2 options:

  • Add a provider name check inside the handlers that populate that field
  • Manually toggle it off in the Metadata field settings page, inside Engagement -> Reader Activation -> Advanced settings, for publishers that don't want it.

I'd go with the latter, favoring the more generic approach.

The contact status handling for Mailchimp also moved to a filter inside the Reader_Activation class. Works but I don't love it. I'd appreciate suggestions on how to implement that requirement without hurting this effort's goal.

By using the new ESP_Sync::can_esp_sync() check, unless Newspack Manager says you're a live site, the sync will not go through without the new NEWSPACK_ALLOW_READER_SYNC. This constant should be set for testing purposes. It's important to inspect how this method works because it aims to be the single point where we ask if syncs should occur.

Regarding this filter, it was built for Newspack Network. It's preserved in this PR but I wonder if we could do this differently and not have another filter messing with sync data. Perhaps the newspack_esp_sync_contact? cc @leogermani

Update

1d198b9 proposes a change regarding the filter mentioned above. The newspack_data_events_reader_registered_metadata filter was removed to favor the new newspack_esp_sync_contact filter. This change, followed by Automattic/newspack-network#87, also allows for the backfilling logic in place for Newspack Network to no longer live in the ESP_Sync class, which was also removed in the commit.

To also accommodate that change, the Teams for Memberships integration filter was changed from newspack_esp_sync_normalize_contact to newspack_esp_sync_contact, which should result in no functional changes.

How to test the changes in this Pull Request:

  1. Set the NEWSPACK_ALLOW_READER_SYNC constant to true
  2. Make sure you have RAS setup with Mailchimp and an audience ID as master list
  3. Visit the Metadata field settings in Engagement -> Reader Activation -> Advanced and confirm all fields are enabled
  4. Register a new reader, watch the logs, and confirm the sync goes through with the correct metadata
  5. Visit the contact page in Mailchimp and confirm the merge fields match the sent data and contact subscription status matches the configured value in RAS settings
  6. Signed in as the new reader, donate and confirm the same process
  7. Make a recurring donation and confirm the last_payment_date, recurring_payment, billing_cycle, subscription_start_date, next_payment_date, membership_status, and total_paid fields are updated with the new data
  8. Purchase a non-donation subscription and confirm product_name and the above fields update with the new data
  9. Subscribe to newsletters using the Newsletter Subscription Form block and confirm the newsletter_selection field updates
  10. Associate the reader to a membership plan and confirm the membership_status, membership_plan, membership_start_date, and membership_end_date updates according to the membership data
  11. Switch your ESP to ActiveCampaign and repeat steps 4-10

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@miguelpeixe miguelpeixe deleted the branch trunk August 29, 2024 16:29
@miguelpeixe miguelpeixe reopened this Aug 29, 2024
@miguelpeixe miguelpeixe changed the base branch from feat/woo-sync-tools to trunk August 29, 2024 18:37
@miguelpeixe miguelpeixe self-assigned this Aug 29, 2024
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Aug 29, 2024
@miguelpeixe miguelpeixe marked this pull request as ready for review August 29, 2024 19:47
@miguelpeixe miguelpeixe requested a review from a team as a code owner August 29, 2024 19:47
@leogermani
Copy link
Contributor

leogermani commented Aug 30, 2024

Regarding this filter, it was Automattic/newspack-network#87. It's preserved in this PR but I wonder if we could do this differently and not have another filter messing with sync data. Perhaps the newspack_esp_sync_contact? cc @leogermani

You decide! In this new strutcture, what should be the right way for a plugin (or another part of the code) to register a new metadata and add it to the payload. Like this does. Later improved by this.

@miguelpeixe
Copy link
Member Author

Thanks, @leogermani!

Just pushed a change with 1d198b9 and Automattic/newspack-network#132. I updated the PR description. This allows for the backfilling logic in place for Newspack Network to no longer live in the ESP_Sync class, which feels good.

Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great!

I think the mailchimp status filter is fine. It's better than some other mailchimp specific things that are inserted in the middle of some methods (like the first/last name handling in the middle of normalize_contact)

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Aug 30, 2024
@miguelpeixe
Copy link
Member Author

I think the mailchimp status filter is fine. It's better than some other mailchimp specific things that are inserted in the middle of some methods (like the first/last name handling in the middle of normalize_contact)

I know: Automattic/newspack-newsletters#1628

@miguelpeixe miguelpeixe merged commit 7080864 into trunk Aug 30, 2024
8 checks passed
@miguelpeixe miguelpeixe deleted the feat/esp-connector-with-sync branch August 30, 2024 21:02
matticbot pushed a commit that referenced this pull request Sep 20, 2024
# [5.4.0-alpha.6](v5.4.0-alpha.5...v5.4.0-alpha.6) (2024-09-20)

### Bug Fixes

* change the current product criteria for sync ([#3416](#3416)) ([28a84bc](28a84bc))
* **esp-sync:** sync Connected Account field ([#3414](#3414)) ([61c02bc](61c02bc))
* hide My Account links if not relevant ([#3394](#3394)) ([0d039d8](0d039d8))
* **phpcs:** specify path in custom ruleset ref ([#3384](#3384)) ([b143e74](b143e74))
* prevent PHP notice while checking my-account page ([#3435](#3435)) ([146a26f](146a26f))
* **ras-sync:** deprecate redundant Signup_Page meta field ([#3439](#3439)) ([61d6de8](61d6de8))
* **reader-registration-block:** fix initial newsletter checkbox state ([1890efe](1890efe))
* replace `newspack_image_credits_placeholder` default value ([#3433](#3433)) ([c754fc2](c754fc2))
* **sync:** method name for `membership_saved` handler ([#3399](#3399)) ([2c0bf26](2c0bf26))
* **sync:** place esp sync admin features behind a constant ([#3438](#3438)) ([20a0970](20a0970))
* **sync:** remove localized number format ([#3434](#3434)) ([2243a5d](2243a5d))

### Features

* add a new action to when a ras setting is updated ([#3357](#3357)) ([35d3492](35d3492))
* **ga4:** detect gate interaction blocks ([#3408](#3408)) ([e14913c](e14913c))
* media kit page handling ([#3358](#3358)) ([4454850](4454850))
* **ras:** sync class ([#3362](#3362)) ([88acbee](88acbee))
* **ras:** unify ESP connector strategy for data events ([#3360](#3360)) ([7080864](7080864))
* **reader-activation:** ESP-related tweaks ([#3381](#3381)) ([ac68b67](ac68b67))
* remove Woo Membersip sync fields ([#3411](#3411)) ([28052e8](28052e8))
* **sync:** add ESP sync notice to RAS wizard ([#3400](#3400)) ([f9acd56](f9acd56))
@miguelpeixe miguelpeixe mentioned this pull request Sep 6, 2024
6 tasks
@matticbot
Copy link
Contributor

🎉 This PR is included in version 5.4.0-alpha.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Oct 3, 2024
# [5.5.0-alpha.1](v5.4.0...v5.5.0-alpha.1) (2024-10-03)

### Bug Fixes

* change the current product criteria for sync ([#3416](#3416)) ([28a84bc](28a84bc))
* **esp-meta:** handle state of the 'Woo Team' meta ([#3352](#3352)) ([ba5ea1e](ba5ea1e))
* **esp-sync:** sync Connected Account field ([#3414](#3414)) ([61c02bc](61c02bc))
* **esp-wc-metadata:** last payment date & amount handling ([#3363](#3363)) ([d1abbfe](d1abbfe))
* **guest-author:** enqueue the guest author admin script selectively ([0bf37af](0bf37af))
* hide My Account links if not relevant ([#3394](#3394)) ([0d039d8](0d039d8))
* make email template fetching deterministic ([#3341](#3341)) ([ace91aa](ace91aa))
* **phpcs:** specify path in custom ruleset ref ([#3384](#3384)) ([b143e74](b143e74))
* prevent PHP notice while checking my-account page ([#3435](#3435)) ([146a26f](146a26f))
* **ras-sync:** deprecate redundant Signup_Page meta field ([#3439](#3439)) ([61d6de8](61d6de8))
* **reader-registration-block:** fix initial newsletter checkbox state ([1890efe](1890efe))
* replace `newspack_image_credits_placeholder` default value ([#3433](#3433)) ([c754fc2](c754fc2))
* **sync:** method name for `membership_saved` handler ([#3399](#3399)) ([2c0bf26](2c0bf26))
* **sync:** place esp sync admin features behind a constant ([#3438](#3438)) ([20a0970](20a0970))
* **sync:** remove localized number format ([#3434](#3434)) ([2243a5d](2243a5d))
* wizards - update type check conditional for `custom_logo` ([#3442](#3442)) ([125f756](125f756))
* woocommerce connection tests ([#3372](#3372)) ([5cea128](5cea128))
* **woocommerce-connection:** handle explicit UTM meta fields meta ([#3371](#3371)) ([bf9e997](bf9e997))

### Features

* add a new action to when a ras setting is updated ([#3357](#3357)) ([35d3492](35d3492))
* **esp-sync:** sync membership data regardless of subscription ([#3353](#3353)) ([9f7d1de](9f7d1de))
* **ga4:** detect gate interaction blocks ([#3408](#3408)) ([e14913c](e14913c))
* **ga:** disable tracking for editors regardless of RA status ([81323c3](81323c3))
* media kit page handling ([#3358](#3358)) ([4454850](4454850))
* **memberships:** add memberships-related body classes ([b56b9d8](b56b9d8))
* **ras:** esp sync tools ([#3359](#3359)) ([d7dd754](d7dd754))
* **ras:** helper method for ESP master list ([#3355](#3355)) ([ec56d5b](ec56d5b))
* **ras:** sync class ([#3362](#3362)) ([88acbee](88acbee))
* **ras:** unify ESP connector strategy for data events ([#3360](#3360)) ([7080864](7080864))
* **reader-activation:** ESP-related tweaks ([#3381](#3381)) ([ac68b67](ac68b67))
* remove Woo Membersip sync fields ([#3411](#3411)) ([28052e8](28052e8))
* **sync:** add ESP sync notice to RAS wizard ([#3400](#3400)) ([f9acd56](f9acd56))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 5.5.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Oct 8, 2024
# [5.5.0](v5.4.1...v5.5.0) (2024-10-08)

### Bug Fixes

* cancelled subscriptions sync ([#3466](#3466)) ([b605a7f](b605a7f))
* change the current product criteria for sync ([#3416](#3416)) ([28a84bc](28a84bc))
* **esp-meta:** handle state of the 'Woo Team' meta ([#3352](#3352)) ([ba5ea1e](ba5ea1e))
* **esp-sync:** sync Connected Account field ([#3414](#3414)) ([61c02bc](61c02bc))
* **esp-wc-metadata:** last payment date & amount handling ([#3363](#3363)) ([d1abbfe](d1abbfe))
* **guest-author:** enqueue the guest author admin script selectively ([0bf37af](0bf37af))
* hide My Account links if not relevant ([#3394](#3394)) ([0d039d8](0d039d8))
* make email template fetching deterministic ([#3341](#3341)) ([ace91aa](ace91aa))
* **phpcs:** specify path in custom ruleset ref ([#3384](#3384)) ([b143e74](b143e74))
* prevent PHP notice while checking my-account page ([#3435](#3435)) ([146a26f](146a26f))
* **ras-sync:** deprecate redundant Signup_Page meta field ([#3439](#3439)) ([61d6de8](61d6de8))
* **reader-registration-block:** fix initial newsletter checkbox state ([1890efe](1890efe))
* replace `newspack_image_credits_placeholder` default value ([#3433](#3433)) ([c754fc2](c754fc2))
* **sync:** method name for `membership_saved` handler ([#3399](#3399)) ([2c0bf26](2c0bf26))
* **sync:** place esp sync admin features behind a constant ([#3438](#3438)) ([20a0970](20a0970))
* **sync:** remove localized number format ([#3434](#3434)) ([2243a5d](2243a5d))
* wizards - update type check conditional for `custom_logo` ([#3442](#3442)) ([125f756](125f756))
* woocommerce connection tests ([#3372](#3372)) ([5cea128](5cea128))
* **woocommerce-connection:** handle explicit UTM meta fields meta ([#3371](#3371)) ([bf9e997](bf9e997))

### Features

* add a new action to when a ras setting is updated ([#3357](#3357)) ([35d3492](35d3492))
* **esp-sync:** sync membership data regardless of subscription ([#3353](#3353)) ([9f7d1de](9f7d1de))
* **ga4:** detect gate interaction blocks ([#3408](#3408)) ([e14913c](e14913c))
* **ga:** disable tracking for editors regardless of RA status ([81323c3](81323c3))
* media kit page handling ([#3358](#3358)) ([4454850](4454850))
* **memberships:** add memberships-related body classes ([b56b9d8](b56b9d8))
* **ras:** esp sync tools ([#3359](#3359)) ([d7dd754](d7dd754))
* **ras:** helper method for ESP master list ([#3355](#3355)) ([ec56d5b](ec56d5b))
* **ras:** sync class ([#3362](#3362)) ([88acbee](88acbee))
* **ras:** unify ESP connector strategy for data events ([#3360](#3360)) ([7080864](7080864))
* **reader-activation:** ESP-related tweaks ([#3381](#3381)) ([ac68b67](ac68b67))
* remove Woo Membersip sync fields ([#3411](#3411)) ([28052e8](28052e8))
* **sync:** add ESP sync notice to RAS wizard ([#3400](#3400)) ([f9acd56](f9acd56))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants